package com.example.service.impl;

import com.example.mapper.TeachMapper;
import com.example.pojo.Teach;
import com.example.service.TeachService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.List;

@Service
public class TeachServiceImp implements TeachService {
    @Autowired
    private TeachMapper teachMapper;
    @Override
    public List<Teach> selectTeachByPid(int pid) {
        return teachMapper.selectTeachByPid(pid);
    }

    @Override
    public List<Teach> selectTeachByUid(int uid) {
        return teachMapper.selectTeachByUid(uid);
    }

    @Override
    public List<Teach> selectAllTeach() {
        return teachMapper.selectAllTeach();
    }

    @Override
    public int insertTeach(int pid,int uid) {
        Teach teach = new Teach();
        teach.setPid(pid);
        teach.setUid(uid);
        return teachMapper.insertTeach(teach);
    }

    @Override
    public int deleteTeachByUid(int uid) {
        return teachMapper.deleteTeachByUid(uid);
    }

    @Override
    public int deleteTeachByPid(int pid) {
        return teachMapper.deleteTeachByPid(pid);
    }

    @Override
    public int updateTeach(int pid,int uid, String startTime) {
        Teach teach = new Teach();
        teach.setPid(pid);
        teach.setUid(uid);
        System.out.println(startTime);
        LocalDateTime localDate=LocalDateTime.parse(startTime, DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
        teach.setStartTime(localDate);
        return teachMapper.insertTeach(teach);
    }
}
